package com.taotao.st3.base.openapi3;

import com.taotao.st3.base.enumhub.CodeTextEnumUtils;
import com.taotao.st3.base.enumhub.enumat.EnumField;
import io.swagger.v3.core.converter.AnnotatedType;
import io.swagger.v3.oas.models.media.Schema;
import org.springdoc.core.customizers.PropertyCustomizer;

import java.lang.annotation.Annotation;

/**
 * <p>
 * springdoc自定义属性解析器之枚举类型
 * </p>
 *
 * @author fanbeibei
 * @version 1.0.0
 * @date 2023/8/14 11:21
 */
public class EnumValuePropertyCustomizer implements PropertyCustomizer {
    @Override
    public Schema customize(Schema property, AnnotatedType type) {
        // 获取属性上的注解
        Annotation[] ctxAnnotations = type.getCtxAnnotations();
        if (null != ctxAnnotations && ctxAnnotations.length > 0) {
            for (Annotation anno : ctxAnnotations) {
                if (anno instanceof EnumField) {
                    EnumField enumField = (EnumField) anno;
                    property.setDescription(property.getDescription() + ",对应的出参名称字段为" + type.getPropertyName()
                            + "_label(若为入参不需要传),枚举值说明:" + CodeTextEnumUtils.getDscr(enumField.value()));
                    break;
                }
            }

        }

        return property;
    }


}
